// pages/collectionGoods/index.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host_product:[],
    loadTitle:'加载更多',
    loading:false,
    loadend:false,
    collectProductList:[],
    limit:8,
    page:1,
  },

  onShow: function () {
    var that = this;
      wx.showLoading({
          mask: true,
          title:'数据加载中...',
      });
    wx.request({
      url: 'https://www.brvpmusic.com/api/collect/list',
      // url: 'https://www.brvpmusic.com/api/products/g7etList',
      data: {
        'cOpenid': wx.getStorageSync('OpenId')
      },
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log('收藏列表获取成功');
        console.log(res.data.body);
        var result = res.data.body;
        that.setData({
          collectProductList: result,
        });
          wx.hideLoading();
        if (0 >= result.length) {
          wx.request({
            url: 'https://www.brvpmusic.com/api/products/recommendProducts',
            // url: 'https://www.brvpmusic.com/api/products/getList',
            method: 'GET',
            header: {
              'Content-Type': 'application/json'
            },
            success: function (res) {
              console.log('推荐列表获取成功');
              console.log(res.data.body);
              var result = res.data.body;
              console.log("结果:" + result);
              that.setData({
                host_product: result,
              });
            },
            fail: function (res) {
              console.log('返回失败');
            }
          })
        }
      },
      fail: function (res) {
        console.log('返回失败');
          wx.hideLoading();
      }
    })
  },
  /**
   * 授权回调
  */
  onLoadFun:function(){
    // this.get_user_collect_product();
    // this.get_host_product();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    

  },
 
  
  /**
   * 取消收藏
  */
  delCollection:function(e){
    var pPid = e.target.dataset.id, that = this;
    console.log("结果:"+pPid);
    wx.request({
      url: 'https://www.brvpmusic.com/api/collect/delete',
      data: {
        'cOpenid': wx.getStorageSync('OpenId'),
        'pPid': pPid
      },
      method: 'GET',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        wx.showToast({
          title: '取消收藏成功',
        })
   
        console.log("走了");
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })
    
  },
  
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
   
  }
})